# Example preprocessing script.
source("..//Week 02//misFunciones.R")

#name cleaning
loansData <- basic_names_cleaning(loansData)

#type conversion 
if(class(loansData$interest.rate) =="character")
{
  loansData$interest.rate <- as.numeric(gsub("%","",loansData$interest.rate,))/100
}
if(class(loansData$debt.to.income.ratio) =="character")
{
  loansData$debt.to.income.ratio <- as.numeric(gsub("%","",loansData$debt.to.income.ratio,))/100
}
loansData$loan.length <- as.numeric(gsub(" months","",loansData$loan.length,))
loansData$loan.purpose <- as.factor(loansData$loan.purpose)
loansData$state <- as.factor(loansData$state)
loansData$fico.range <- as.factor(loansData$fico.range)
loansData$employment.length <- as.factor(loansData$employment.length)

# clean irregular values
# amount funded can not be negative
loansData$amount.funded.by.investors[loansData$amount.funded.by.investors < 0] <- NA
#we have to look at this data carefuly because is too much money for people asking for a credit
loansData[loansData$monthly.income > 40000,]

basic_summarize_data(loansData)